/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:57 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class DangkykhoahocDAL : SqlProvider<DangkykhoahocEntity>
    {
        static DangkykhoahocDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                DangkykhoahocEntity entity = new DangkykhoahocEntity();
				entity.PK_iDangkykhoahocID = Int64.Parse("0"+dr["PK_iDangkykhoahocID"].ToString());
				entity.FK_iKhoahocID = Int64.Parse("0"+dr["FK_iKhoahocID"].ToString());
				entity.FK_iHocvienID = Int64.Parse("0"+dr["FK_iHocvienID"].ToString());
				entity.dNgaydangky =String.IsNullOrEmpty(dr["dNgaydangky"].ToString())?DateTime.Now:DateTime.Parse(dr["dNgaydangky"].ToString());
				entity.iTrangthai = Int16.Parse("0"+dr["iTrangthai"].ToString());
                return entity;
            };
        }
        public static DangkykhoahocEntity GetOne(Int64 PK_iDangkykhoahocID)
        {
            string cmdName = "spDangkykhoahoc_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iDangkykhoahocID", PK_iDangkykhoahocID);
            DangkykhoahocEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static DangkykhoahocEntity GetByFK_iKhoahocIDAndFK_iHocvienID(Int64 FK_iKhoahocID, Int32 FK_iHocvienID)
        {
            string cmdName = "spDangkykhoahoc_GetByFK_iKhoahocIDAndFK_iHocvienID";
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter("@FK_iKhoahocID", FK_iKhoahocID);
            p[1] = new SqlParameter("@FK_iHocvienID", FK_iHocvienID);
            DangkykhoahocEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<DangkykhoahocEntity> GetAll()
        {
            string cmdName = "spDangkykhoahoc_Get";
            return GetList(cmdName);
        }
        public static List<DangkykhoahocEntity> GetByFK_iKhoahocID(Int64 FK_iKhoahocID)
		{
			string cmdName = "spDangkykhoahoc_GetByFK_FK_iKhoahocID";
			SqlParameter p = new SqlParameter("@FK_iKhoahocID",FK_iKhoahocID);
			List<DangkykhoahocEntity> list = GetList(cmdName, p);
			return list;
		}public static List<DangkykhoahocEntity> GetByFK_iHocvienID(Int64 FK_iHocvienID)
		{
			string cmdName = "spDangkykhoahoc_GetByFK_FK_iHocvienID";
			SqlParameter p = new SqlParameter("@FK_iHocvienID",FK_iHocvienID);
			List<DangkykhoahocEntity> list = GetList(cmdName, p);
			return list;
		}
        public static int Add(DangkykhoahocEntity entity)
        {
            string cmdName = "spDangkykhoahoc_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(DangkykhoahocEntity entity)
        {
            string cmdName = "spDangkykhoahoc_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 PK_iDangkykhoahocID)
        {
            string cmdName = "spDangkykhoahoc_Delete";
            SqlParameter p = new SqlParameter("@PK_iDangkykhoahocID", PK_iDangkykhoahocID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(DangkykhoahocEntity entity)
        {
            SqlParameter[] p = new SqlParameter[5];
			p[0] = new SqlParameter("@PK_iDangkykhoahocID", entity.PK_iDangkykhoahocID);
			p[1] = new SqlParameter("@FK_iKhoahocID", entity.FK_iKhoahocID);
			p[2] = new SqlParameter("@FK_iHocvienID", entity.FK_iHocvienID);
			p[3] = new SqlParameter("@dNgaydangky", entity.dNgaydangky);
			p[4] = new SqlParameter("@iTrangthai", entity.iTrangthai);
            return p;
        }
        #endregion
       
    }
}